home *** CD-ROM | disk | FTP | other *** search
/ Freelog 125 / Freelog_MarsAvril2015_No125.iso / Musique / Quod Libet / quodlibet-3.3.0-installer.exe / bin / quodlibet / ext / events / zeitgeist_client.pyc (.txt) < prev   
Python Compiled Bytecode  |  2014-12-31  |  3KB  |  69 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 2.7)
  3.  
  4. import os
  5. import sys
  6. if os.name == 'nt' or sys.platform == 'darwin':
  7.     from quodlibet.plugins import PluginNotSupportedError
  8.     raise PluginNotSupportedError
  9. import time
  10.  
  11. try:
  12.     import __builtin__
  13.     old_builtin = __builtin__.__dict__.copy()
  14.     from zeitgeist.client import ZeitgeistClient
  15.     from zeitgeist.datamodel import Event, Subject
  16.     from zeitgeist.datamodel import Interpretation, Manifestation
  17.     __builtin__.__dict__.update(old_builtin)
  18. except ImportError:
  19.     e = None
  20.     from quodlibet import plugins
  21.     raise plugins.MissingModulePluginException('zeitgeist') if hasattr(plugins, 'MissingModulePluginException') else e
  22.  
  23. from quodlibet.plugins.events import EventPlugin
  24.  
  25. class Zeitgeist(EventPlugin):
  26.     PLUGIN_ID = 'zeitgeist'
  27.     PLUGIN_NAME = _('Event Logging')
  28.     PLUGIN_DESC = _('Send song events to the Zeitgeist event logging service')
  29.     PLUGIN_ICON = 'gtk-network'
  30.     PLUGIN_VERSION = '0.1'
  31.     
  32.     def enabled(self):
  33.         self.client = ZeitgeistClient()
  34.         self._Zeitgeist__stopped_by_user = False
  35.  
  36.     
  37.     def disabled(self):
  38.         del self.client
  39.         del self._Zeitgeist__stopped_by_user
  40.  
  41.     
  42.     def plugin_on_song_started(self, song):
  43.         if self._Zeitgeist__stopped_by_user:
  44.             manifestation = Manifestation.USER_ACTIVITY
  45.         else:
  46.             manifestation = Manifestation.SCHEDULED_ACTIVITY
  47.         self._Zeitgeist__send_event(song, Interpretation.ACCESS_EVENT, manifestation)
  48.  
  49.     
  50.     def plugin_on_song_ended(self, song, stopped):
  51.         self._Zeitgeist__stopped_by_user = stopped
  52.         if stopped:
  53.             manifestation = Manifestation.USER_ACTIVITY
  54.         else:
  55.             manifestation = Manifestation.SCHEDULED_ACTIVITY
  56.         self._Zeitgeist__send_event(song, Interpretation.LEAVE_EVENT, manifestation)
  57.  
  58.     
  59.     def __send_event(self, song, interpretation, manifestation):
  60.         if not song:
  61.             return None
  62.         None('event: interpretation=%s, manifestation=%s' % (interpretation.__name__, manifestation.__name__))
  63.         subject = Subject.new_for_values(uri = song('~uri'), interpretation = Interpretation.AUDIO, manifestation = Manifestation.FILE_DATA_OBJECT)
  64.         event = Event.new_for_values(timestamp = int(time.time() * 1000), interpretation = interpretation, manifestation = manifestation, actor = 'application://quodlibet.desktop', subjects = [
  65.             subject])
  66.         self.client.insert_event(event)
  67.  
  68.  
  69.